﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Estimate
{
    public partial class formManualFirm : FormMDIChildTemplate 
    {
        public formManualFirm()
        { InitializeComponent(); }

        private void saveToolStripButton_Click(object sender, EventArgs e)
        { root.Submit(); LoadFirms(); }

        private void formManualFirm_Load(object sender, EventArgs e)
        { LoadFirms(); root.TranslateGrid(gridFirms); }

        private void LoadFirms()
        {
            var firms = from x in context.Firms orderby x.FirmName select x;
            var firmTypes = from x in context.FirmTypes select x;
            firmBindingSource.DataSource = firms;
            firmTypebindingSource.DataSource = firmTypes.ToList();
        }

        private void gridFirms_CellParsing(object sender, DataGridViewCellParsingEventArgs e)
        {
            string s = e.Value as string;
            FirmType firmType =
                (from x in firmTypebindingSource.OfType<FirmType>() where x.ToString() == s select x).FirstOrDefault();
            e.Value = firmType;
            e.ParsingApplied = true;
        }
    }
}
